package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleParam;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

@Api(tags = "车辆管理模块")
@Slf4j
@RestController
@RequestMapping("/v1/vehicle")
public class VechicleController {

    @Autowired
    private VehicleService vehicleService;

    @GetMapping("/select")
    public JsonResult selectvehicle(VehicleQuery vehicleQuery){
        log.debug("查询车辆信息参数: vehicleQuery={}",vehicleQuery);
        List<VehicleVO> list = vehicleService.selectvehicle(vehicleQuery);
        return JsonResult.ok(list);
    }


    @PostMapping("/save")
    public JsonResult saveVehicle(VehicleParam vehicleParam) throws ParseException {
        log.debug("新增的参数信息: vehicleParam={}",vehicleParam);
        vehicleService.saveVehicle(vehicleParam);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{id}")
    public JsonResult deleteVehicle(@PathVariable Long id){
        log.debug("删除的信息参数: id={}",id);
        vehicleService.delete(id);
        return JsonResult.ok();
    }

    @PostMapping("/unbind/{id}")
    public JsonResult unbindVehicle(@PathVariable("id") Long vehicleId){
        log.debug("解绑车辆: ,vehicleId={}",vehicleId);
        vehicleService.unbindVehicle(vehicleId);
        return JsonResult.ok();
    }

    @PostMapping("/bind/{geoId}/{Id}")
    public JsonResult bindVehicle(@PathVariable("geoId") Long geofenceId,
                                  @PathVariable("Id") Long vehicleId){
        log.debug("绑定车辆:geofenceId={},vehicleId={}",geofenceId,vehicleId);
        vehicleService.bindVehicle(geofenceId,vehicleId);
        return JsonResult.ok();
    }
}
